
#ifndef __SX1276_HAL_H__
#define __SX1276_HAL_H__
#include <stdio.h>
#include "stm32f10x.h"

/*下面是和拨码开关相连接的管脚的配置*/
#define			LORA_ADDR_BIT0_PORT				GPIOB
#define			LORA_ADDR_BIT0_PIN				GPIO_Pin_15
#define			LORA_ADDR_BIT0_CLK				RCC_APB2Periph_GPIOB

#define			LORA_ADDR_BIT1_PORT				GPIOB
#define			LORA_ADDR_BIT1_PIN				GPIO_Pin_14
#define			LORA_ADDR_BIT1_CLK				RCC_APB2Periph_GPIOB

#define			LORA_ADDR_BIT2_PORT				GPIOB
#define			LORA_ADDR_BIT2_PIN				GPIO_Pin_13
#define			LORA_ADDR_BIT2_CLK				RCC_APB2Periph_GPIOB

#define			LORA_ADDR_BIT3_PORT				GPIOB
#define			LORA_ADDR_BIT3_PIN				GPIO_Pin_12
#define			LORA_ADDR_BIT3_CLK				RCC_APB2Periph_GPIOB
/*!
 * SX1276 RESET I/O definitions
 */
#define			RESET_CLK				RCC_APB2Periph_GPIOA
#define RESET_IOPORT                                GPIOA
#define RESET_PIN                                   GPIO_Pin_3

/*!
 * SX1276 SPI NSS I/O definitions    即片选
 */
#define			NSS_CLK				RCC_APB2Periph_GPIOC
#define NSS_IOPORT                                  GPIOC
#define NSS_PIN                                     GPIO_Pin_5   

typedef enum
{
    RADIO_RESET_OFF,
    RADIO_RESET_ON,
}tRadioResetState;


void delay_nms(uint16_t time);
/*!
 * \brief Initializes the radio interface I/Os
 */
void SX1276InitIo( void );

/*!
 * \brief Set the radio reset pin state
 * 
 * \param state New reset pin state
 */
void SX1276SetReset( uint8_t state );

/*!
 * \brief Writes the radio register at the specified address
 *
 * \param [IN]: addr Register address
 * \param [IN]: data New register value
 */
void SX1276Write( uint8_t addr, uint8_t data );

/*!
 * \brief Reads the radio register at the specified address
 *
 * \param [IN]: addr Register address
 * \param [OUT]: data Register value
 */
void SX1276Read( uint8_t addr, uint8_t *data );

/*!
 * \brief Writes multiple radio registers starting at address
 *
 * \param [IN] addr   First Radio register address
 * \param [IN] buffer Buffer containing the new register's values
 * \param [IN] size   Number of registers to be written
 */
void SX1276WriteBuffer( uint8_t addr, uint8_t *buffer, uint8_t size );

/*!
 * \brief Reads multiple radio registers starting at address
 *
 * \param [IN] addr First Radio register address
 * \param [OUT] buffer Buffer where to copy the registers data
 * \param [IN] size Number of registers to be read
 */
void SX1276ReadBuffer( uint8_t addr, uint8_t *buffer, uint8_t size );

/*!
 * \brief Writes the buffer contents to the radio FIFO
 *
 * \param [IN] buffer Buffer containing data to be put on the FIFO.
 * \param [IN] size Number of bytes to be written to the FIFO
 */
void SX1276WriteFifo( uint8_t *buffer, uint8_t size );

/*!
 * \brief Reads the contents of the radio FIFO
 *
 * \param [OUT] buffer Buffer where to copy the FIFO read data.
 * \param [IN] size Number of bytes to be read from the FIFO
 */
void SX1276ReadFifo( uint8_t *buffer, uint8_t size );


/*
 * \brief Writes the external RxTx pin value
 *
 * \remark see errata note
 *
 * \param [IN] txEnable [1: Tx, 0: Rx]
 */
//inline void SX1276WriteRxTx( uint8_t txEnable );



#endif //__SX1276_HAL_H__
